#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Módulos 
import sys, gtk, pygame, utils, objetos
from pygame.locals import *
# Constantes
 
# Clases
# ---------------------------------------------------------------------
class ObjGrafico(pygame.sprite.Sprite):
    def __init__(self, path, x, y, t=True ):
        pygame.sprite.Sprite.__init__(self)
        self.image = utils.load_image(path, t)
        self.rect = self.image.get_rect()
        self.rect.centerx = x*utils.RES
        self.rect.centery = y*utils.RES


# ---------------------------------------------------------------------
 
# Funciones
# ---------------------------------------------------------------------
 
 
# ---------------------------------------------------------------------
 
def dibujar(screen,cursor_picture, clock):
    	salir = 0
    	background_image = utils.load_image('images/fondo2.png')

    	#boton de la flecha para continuar
    	btn_adelante = objetos.BotonAdelante()
    	btn_atras = objetos.BotonAtras()

    	#texto superior derecho que indica el numero de clase
    	clase2, clase2_rect = utils.texto_clase("Clase 2", 750*utils.RES, 15*utils.RES)
        titulo1, titulo1_rect = utils.textotlb("TODOS PODEMOS", 120*utils.RES, 100*utils.RES, 28, color=(255, 0, 0))
        titulo2, titulo2_rect = utils.textotlb("HACER ALGO", 120*utils.RES, 150*utils.RES, 28, color=(255, 0, 0))    


	beto = ObjGrafico("images/clase2_personajes_b.png", 270,270)
	beto_dialog = ObjGrafico("images/clase2_personajes_b_dialog.png", 440,110)
	show_dialog_beto = False

	trueno = ObjGrafico("images/clase2_personajes_perro.png", 560,420)
	trueno_dialog = ObjGrafico("images/clase2_personajes_perro_dialog.png", 560,280)
	show_dialog_trueno = False


	frames = 1
	cant_frames = 50
    	while salir == 0:

	    	# Pump GTK messages.
		while gtk.events_pending():
			gtk.main_iteration()
			
		for eventos in pygame.event.get():
			if eventos.type == QUIT:
				sys.exit(0)
			elif eventos.type == pygame.VIDEORESIZE:
			   pygame.display.set_mode(eventos.size, pygame.RESIZABLE)	
			elif eventos.type == MOUSEBUTTONDOWN:
				if btn_adelante.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 11
					btn_adelante.sonido.play()	
				elif btn_atras.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 9
					btn_atras.sonido.play()	

				
		# Realiza la animacion del texto				

		screen.blit(background_image, (0, 0))
		screen.blit(clase2, clase2_rect)
		screen.blit(titulo1, titulo1_rect)
		screen.blit(titulo2, titulo2_rect)
		
		if frames > (1 * cant_frames) :
			screen.blit(trueno.image, trueno.rect)

		if frames > (2 * cant_frames) :
			screen.blit(trueno_dialog.image, trueno_dialog.rect)

		if frames > (3 * cant_frames) : 
			screen.blit(beto.image, beto.rect)

		if frames > (4 * cant_frames) :
			screen.blit(beto_dialog.image, beto_dialog.rect)


		if frames > (11 * cant_frames) :
			frames = 0

		screen.blit(btn_adelante.image, btn_adelante.rect)
		screen.blit(btn_atras.image, btn_atras.rect)		
		screen.blit(cursor_picture, pygame.mouse.get_pos())
		pygame.display.flip()

		# Try to stay at 30 FPS
		clock.tick(30)
	    	frames = frames + 1 

	return salir


# ./TestGame.py 
def main():
	
	pygame.init()
	screen = pygame.display.set_mode((int(800*utils.RES), int(520*utils.RES)), pygame.RESIZABLE) #pygame.display.get_surface() #

	# Fake a Sugar cursor for the pyGame canvas area
	pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
	cursor_picture = pygame.image.load('images/standardcursor.png')
	cursor_picture.convert_alpha() 
	clock = pygame.time.Clock()
	dibujar(screen,cursor_picture,clock)

if __name__ == '__main__':
   main()
